<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Origami::Encryption::ARC4</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Origami::Encryption::ARC4</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/origami/encryption_rb.html">
                origami/encryption.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Pure Ruby implementation of the aRC4 symmetric algorithm
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000278">cipher</a>&nbsp;&nbsp;
      <a href="#M000276">decrypt</a>&nbsp;&nbsp;
      <a href="#M000280">decrypt</a>&nbsp;&nbsp;
      <a href="#M000275">encrypt</a>&nbsp;&nbsp;
      <a href="#M000279">encrypt</a>&nbsp;&nbsp;
      <a href="#M000277">new</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000276" class="method-detail">
        <a name="M000276"></a>

        <div class="method-heading">
          <a href="#M000276" class="method-signature">
          <span class="method-name">decrypt</span><span class="method-args">(key, data)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Decrypts data using the given key
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000276-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000276-source">
<pre>
     <span class="ruby-comment cmt"># File origami/encryption.rb, line 485</span>
485:       <span class="ruby-keyword kw">def</span> <span class="ruby-constant">ARC4</span>.<span class="ruby-identifier">decrypt</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
486:         <span class="ruby-constant">ARC4</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">key</span>).<span class="ruby-identifier">decrypt</span>(<span class="ruby-identifier">data</span>)
487:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000275" class="method-detail">
        <a name="M000275"></a>

        <div class="method-heading">
          <a href="#M000275" class="method-signature">
          <span class="method-name">encrypt</span><span class="method-args">(key, data)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Encrypts data using the given key
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000275-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000275-source">
<pre>
     <span class="ruby-comment cmt"># File origami/encryption.rb, line 478</span>
478:       <span class="ruby-keyword kw">def</span> <span class="ruby-constant">ARC4</span>.<span class="ruby-identifier">encrypt</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">data</span>)
479:         <span class="ruby-constant">ARC4</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">key</span>).<span class="ruby-identifier">encrypt</span>(<span class="ruby-identifier">data</span>)
480:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000277" class="method-detail">
        <a name="M000277"></a>

        <div class="method-heading">
          <a href="#M000277" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(key)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates and initialises a <a href="ARC4.html#M000277">new</a> aRC4
generator using given key
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000277-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000277-source">
<pre>
     <span class="ruby-comment cmt"># File origami/encryption.rb, line 492</span>
492:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">key</span>)
493:         <span class="ruby-ivar">@state</span> = <span class="ruby-identifier">init</span>(<span class="ruby-identifier">key</span>)
494:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000278" class="method-detail">
        <a name="M000278"></a>

        <div class="method-heading">
          <a href="#M000278" class="method-signature">
          <span class="method-name">cipher</span><span class="method-args">(data)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Encrypt/<a href="ARC4.html#M000276">decrypt</a> data with the aRC4
encryption algorithm
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000278-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000278-source">
<pre>
     <span class="ruby-comment cmt"># File origami/encryption.rb, line 499</span>
499:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cipher</span>(<span class="ruby-identifier">data</span>)
500:       
501:         <span class="ruby-identifier">output</span> = <span class="ruby-value str">&quot;&quot;</span>
502:         <span class="ruby-identifier">i</span>, <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>, <span class="ruby-value">0</span>
503:         <span class="ruby-identifier">data</span>.<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">byte</span><span class="ruby-operator">|</span>
504:           <span class="ruby-identifier">i</span> = <span class="ruby-identifier">i</span>.<span class="ruby-identifier">succ</span> <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>
505:           <span class="ruby-identifier">j</span> = (<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@state</span>[<span class="ruby-identifier">i</span>]) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>
506:           
507:           <span class="ruby-ivar">@state</span>[<span class="ruby-identifier">i</span>], <span class="ruby-ivar">@state</span>[<span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@state</span>[<span class="ruby-identifier">j</span>], <span class="ruby-ivar">@state</span>[<span class="ruby-identifier">i</span>]
508:           
509:           <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-ivar">@state</span>[<span class="ruby-ivar">@state</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">+</span> <span class="ruby-ivar">@state</span>[<span class="ruby-identifier">j</span>] <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>] <span class="ruby-operator">^</span> <span class="ruby-identifier">byte</span>).<span class="ruby-identifier">chr</span>
510:         <span class="ruby-keyword kw">end</span>
511:       
512:         <span class="ruby-identifier">output</span>
513:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000280" class="method-detail">
        <a name="M000280"></a>

        <div class="method-heading">
          <span class="method-name">decrypt</span><span class="method-args">(data)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="ARC4.html#M000278">cipher</a>
</p>
        </div>
      </div>

      <div id="method-M000279" class="method-detail">
        <a name="M000279"></a>

        <div class="method-heading">
          <span class="method-name">encrypt</span><span class="method-args">(data)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="ARC4.html#M000278">cipher</a>
</p>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>